#include "AudioManager.h"
#include "../SGD Wrappers/CSGD_XAudio2.h"

AudioManager::AudioManager(void)
{
}


AudioManager::~AudioManager(void)
{
}


AudioManager* AudioManager::GetInstance( void )
{
	static AudioManager instance;

	return &instance;
}



void AudioManager::Initialize()
{
	xA = CSGD_XAudio2::GetInstance();
}

void AudioManager::addMusic(string stateName, int musID)
{
	musicIDs.emplace(stateName, musID);
}
void AudioManager::addSFX(string sfxName, int sfxID)
{
	sfxIDs.emplace(sfxName, sfxID);
}

void AudioManager::startMusic(string curState)
{
	if(musicIDs.at(curState) != -1)
	{
		xA->MusicPlaySong(musicIDs.at(curState), true);
	}
}
void AudioManager::switchMusic(string curState, string newState)
{
//	if(!xA->MusicIsSongPlaying(musicIDs.at(curState)))
		xA->MusicStopSong(musicIDs.at(curState));
	if(musicIDs.at(curState) != -1)
	{
		if(!xA->MusicIsSongPlaying(musicIDs.at(newState)))
			xA->MusicPlaySong(musicIDs.at(newState), true);
	}
}

void AudioManager::playSFX(string sfxName)
{
	if(sfxIDs.at(sfxName) != -1)
	{
		if(!xA->SFXIsSoundPlaying(sfxIDs.at(sfxName)))
			xA->SFXPlaySound(sfxIDs.at(sfxName));
	}
}